package org.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.bean.O2ranksongs;
import org.dao.HotSongsDao;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;


public class HotSongsDaoImpl extends HibernateDaoSupport implements HotSongsDao {

	@SuppressWarnings("rawtypes")
	public List queryForPageHotSongs(final String hql,final int offset,final int length){   
		List list = getHibernateTemplate().executeFind(new HibernateCallback(){   
		public Object doInHibernate(Session session) throws HibernateException,SQLException{  
			Query query = session.createQuery(hql);
			query.setFirstResult(offset);   
			query.setMaxResults(length);  
			List list = query.list(); 
			
			return list;}   
		});
		return list;		
}
	
	
	public int getAllRowCount(String hql) {
		return getHibernateTemplate().find(hql).size();
	}


	@Override
	public O2ranksongs SelectMusicByid(int mid) {
		
		O2ranksongs o2ranksongs = (O2ranksongs)this.getHibernateTemplate().get(O2ranksongs.class, mid);
		
		return o2ranksongs;
	}



}
